package com.zhuiYun.project.api.syslog.service.impl;

import com.zhuiYun.project.api.syslog.entity.ImageFile;
import com.zhuiYun.project.api.syslog.entity.SysUser;
import com.zhuiYun.project.api.syslog.mapper.SysMapper;
import com.zhuiYun.project.api.syslog.service.SysService;
import com.zhuiYun.project.common.response.CommonResult;
import com.zhuiYun.project.util.UploadFileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @ClassName SysServiceImpl
 * @Description TODO
 * @Author wuwan
 * @Date 2023/8/11 15:03
 **/
@Service
public class SysServiceImpl implements SysService {
    @Autowired
    private SysMapper sysMapper;

    @Resource
    UploadFileUtils uploadFileUtils;

    /*
    * @Author wuwan
    * @Description 全查方法
    * @Date 2023/8/12 14:19
    * @Return
    * @param null
    */
    @Override
    public CommonResult sysqueryall() {
        List<SysUser> sysQueryall = sysMapper.sysqueryall();
        return CommonResult.ok(sysQueryall);
    }

    /*
    * @Author wuwan
    * @Description 添加 图片上传同步查询
    * @Date 2023/8/12 14:19
    * @Return
    * @param null
    */
    @Override
    @Transactional
    public CommonResult Sysinsert(MultipartFile file,SysUser sysUser) {
        sysUser.setCreateTime(new Date());
        sysUser.setUpdateTime(new Date());
        sysUser.setDelFlag(0);
        Integer sysInsertrole = sysMapper.sysinsertrole(sysUser);
        Integer id = sysUser.getId();
        sysUser.setRoleId(id);
        String s = uploadFileUtils.uploadFile(file);
        if (s == ""){
            return CommonResult.error("图片信息有误");
        }
        System.out.println(s);
        sysUser.setImg(s);

        ImageFile imageFile=new ImageFile();
        imageFile.setImageName(s);

        Integer insertimage = sysMapper.insertimage(imageFile);
        Integer sysInsert = sysMapper.sysinsert(sysUser);
        return CommonResult.ok(123);
    }

}
